package pack;

public class fibo
{
	public static void main(String[] args)
	{
		long start;
		
		start = System.nanoTime();
		System.out.println(fibo(7));
        System.out.println("Time of running: "+(System.nanoTime()-start)+" nanosec");
        
		start = System.nanoTime();
		System.out.println(fibo_rec(10));
        System.out.println("Time of running: "+(System.nanoTime()-start)+" nanosec");
	}

	public static int fibo_rec(int n)
	{
		if(n <= 0) return 0;
		else if(n == 1) return 1;
		else return fibo_rec(n-1) + fibo_rec(n-2);
	}
	
	public static int fibo(int n)
	{
        int a = 1, b = 1;
        int fib = 2, i = 2;
        while (i < n)
        {
            fib = a + b;
            a = b;
            b = fib;
            i++;
        }
        return fib;
    }
}
